$(function() {
	$('#vue_vm_list div').hide();
});

var elderBeHospital = {
	beHospitalId: '',
	elderId: '',
	subjectRoomId: getLoginedUser().subjectRoomId,
	subjectRoomName: getLoginedUser().subjectRoomName,
	houseTypeId: '',
	houseTypeName: '',
	userVipCardId: '',
	vipCardRelation: '',
	buildingId: '',
	buildingName: '',
	floorId: '',
	floorName: '',
	roomId: '',
	roomName: '',
	bedId: '',
	bedNumber: '',
	nursingCostId: '',
	nursingDesc: '',
	baseServiceCostId: '',
	baseServiceDesc: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	houseTypeType: '',
	beType: '',
	bedStatus: '',
};

var view = {
	data: elderBeHospital
};

var vue_vm = new Vue({
	el: '#vue_vm',
	data: view
});

function save() {
	//view.data.elderId = getCheckedElderId();
	view.data.subjectRoomId = $('#subjectRoom_select').val();
	/*
	view.data.buildingId = $('#building_cond_select').val();
	view.data.floorId = $('#floor_cond_select').val();
	*/
	
	view.data.elderId = $('input:radio[name="elderId"]:checked').val();
	view.data.elderName = $('input:radio[name="elderId"]:checked').attr('elderName');
	view.data.vipCardRelation = $('#vipCardRelation').val();
	view.data.nursingCostId = $('#nursingCost_select').val();
	view.data.baseServiceCostId = $('#baseServiceCost_select').val();
	view.data.nursingDesc = view.data.nursingCostName;
	view.data.baseServiceDesc = view.data.serviceName;
	view.data.bedNumber = (view.data.bedNumber==''? 0: parseInt(view.data.bedNumber));
	view.data.houseTypeType = (view.data.houseTypeType==''? 0: parseInt(view.data.houseTypeType));
	view.data.beType = (view.data.beType==''? 0: parseInt(view.data.beType));
	view.data.bedStatus = (view.data.bedStatus==''? 0: parseInt(view.data.bedStatus));
	
	if(!view.data.elderId || view.data.elderId=='') {
		alert('请选择长者');
		return;
	}
	if(!view.data.subjectRoomId || view.data.subjectRoomId=='') {
		alert('请选择科室');
		return;
	}
	/*
	if(view.data.userVipCardId=='') {
		alert('请选择长者的VIP卡');
		return;
	}
	*/
	
	if(view.data.houseTypeId=='') {
		alert('请选择户型');
		return;
	}
	
	if(view.data.buildingId=='' || view.data.floorId=='' || view.data.bedId=='') {
		alert('请选择楼房、楼层、床位');
		return;
	}
	
	if(view.data.nursingCostId=='') {
		alert('请选择护理');
		return;
	}
	
	if(view.data.baseServiceCostId=='') {
		alert('请选择基础服务');
		return;
	}
	
	var houseTypeType = $('input:radio[name="houseTypeType"]:checked').val();
	if(houseTypeType=='vipCard') {
		view.data.houseTypeType = 1;
		view.data.bedCostId = null;
		view.data.bedCostPrice = null;
		view.data.subsidization = null;
		view.data.subsidizationValue = null;
		view.data.consumptionWay = null;
		view.data.discount = null;
		view.data.consDeductionWay = null;
		view.data.consumptionType = null;
	}else if(houseTypeType=='ordinary') {
		view.data.houseTypeType = 2;
		view.data.userVipCardId = null;
	}

	save_basic(path+'/elderBeHospital/save', {elderBeHospital:view.data}, function(response) {
		alert('入院登记成功');
		window.open('0zhuyang.html?elderBeHospitalId='+response.data[0].beHospitalId);
	});
}

function findAll() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/elderBeHospital/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/elderBeHospital/deleteBatch');
}

function getCheckedElderId() {
	$('#vue_vm_list ul').each(function() {
		if($(this).find('.magic-checkbox').is(':checked')) {
			var elderId = $(this).find('.magic-checkbox').attr('id');
			return elderId;
		}
	});
}